//this module offers functions to access messages

#include "message.h"

/* getters */

int32_t message_get_from(message* target){
  return target->from;
}

int32_t message_get_to(message* target){
  return target->to;
}

int8_t message_get_data_flag(message* target){
  return target->data_flag;
}

int32_t message_get_priority(message* target){
  return target->priority;
}

int8_t message_get_in_use(message* target){
  return target->in_use;
}

char* message_get_str_value(message* target){
  if(target->data_flag == STR_DATA)
    return target->data.str_data;
  return NULL;
}

int32_t message_get_int_value(message* target){
  if(target->data_flag == INT_DATA)
    return target->data.int_data;
  return 0;
}

/* setters */

void message_set_from(message* target, int32_t from){
  target->from = from;
}

void message_set_to(message* target, int32_t to){
  target->to = to;
}

void message_set_data_flag(message* target, int8_t data_flag){
  target->data_flag = data_flag;
}

void message_set_priority(message* target, int32_t priority){
  target->priority = priority;
}

void message_set_in_use(message* target, int8_t in_use){
  target->in_use = in_use;
}

void message_set_int_value(message* target, int32_t value){
  target->data_flag = INT_DATA;
  target->data.int_data = value;
}

void message_set_str_value(message* target, char* value){
  target->data_flag = STR_DATA;
  strncpy(target->data.str_data, value, MAX_LENGTH_DATA);
}

/* copies the message pointed by m2 into m1 */
void messcpy(message* m1, message* m2){
  m1->from = m2->from;
  m1->to = m2->to;
  m1->priority = m2->priority;
  m1->data_flag = m2->data_flag;
  if(m2->data_flag == INT_DATA)
    m1->data.int_data = m2->data.int_data;
  else
    strncpy(m1->data.str_data,m2->data.str_data,MAX_LENGTH_DATA);
}
